def out(n: int, k: int) -> int:
    list1 = list(range(1,n+1, 1))
    while len(list1) != 1:
        o = k%len(list1)
        list1 = list1[o-1:] + list1[:o-1]
        del list1[0]
    return list1[0]

assert out(5,7) == 4
assert out(9,7) == 2
assert out(100,20) == 10